﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;


namespace CommonLib
{
	/// <summary>
	/// 资源管理者提供资源配置与路径
	/// </summary>
	/// <typeparam name="K"></typeparam>
	public abstract class ResourceManagerBase<K> : LazySingleton<K> 
		where K : ResourceManagerBase<K>
	{
		
		protected ResourceManagerBase(string _rootPath)
		{
			RootPath = _rootPath;
			PathDictionary = new Dictionary<AppPath, string>() {
				{ AppPath.DataPath, Path.Combine( Application.dataPath, RootPath) },
				{ AppPath.PersistentDataPath, Path.Combine( Application.persistentDataPath, RootPath) },
				{ AppPath.StreamingAssets, Path.Combine( Application.streamingAssetsPath, RootPath) },
				{ AppPath.Resource, RootPath }
			};
		}
		
		
		public bool IsInit { get; protected set; } = false;

		public string RootPath { get; protected set; } = "";



		protected Dictionary<AppPath, string> PathDictionary;

		virtual public string GetPath(AppPath appPath, string path)
			=> PathDictionary.ContainsKey(appPath) ?  Path.Combine(PathDictionary[appPath], path) : path;
	}

	public enum AppPath
	{
		Resource = 0,
		StreamingAssets = 1,
		DataPath = 2,
		PersistentDataPath = 3
	}
}